#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

string caozuo(string s, int n)
{
    if (n == 1)
    {
        for (int i = 0; i < s.size(); i++)
        {
            s[i] = !(s[i] - '0') + '0';
        }
    }
    else if (n == 2)
    {
        for (int i = 0; i < s.size(); i += 2)
        {
            s[i] = !(s[i] - '0') + '0';
        }
    }
    else if (n == 3)
    {
        for (int i = 1; i < s.size(); i+=2)
        {
            s[i] = !(s[i] - '0') + '0';
        }
    }
    else if (n == 4)
    {
        for (int i = 0; i < s.size(); i += 3)
        {
            s[i] = !(s[i] - '0') + '0';
        }
    }
    else if (n == 5)
    {
        for (int i = 0; i < s.size(); i++)
        {
            s[i] = !(s[i] - '0') + '0';
        }
        for (int i = 0; i < s.size(); i += 3)
        {
            s[i] = !(s[i] - '0') + '0';
        }
    }
    else if (n == 6)
    {
        for (int i = 0; i < s.size(); i += 2)
        {
            s[i] = !(s[i] - '0') + '0';
        }
        for (int i = 0; i < s.size(); i += 3)
        {
            s[i] = !(s[i] - '0') + '0';
        }
    }
    else if (n == 7)
    {
        for (int i = 1; i < s.size(); i+=2)
        {
            s[i] = !(s[i] - '0') + '0';
        }
        for (int i = 0; i < s.size(); i += 3)
        {
            s[i] = !(s[i] - '0') + '0';
        }
    }
    return s;
}
bool ifst(string s, const vector<int>& p1, const vector<int>& p2)
{
    for (int i = 0; i < p1.size(); i++)
    {
        if (s[p1[i] - 1] == '0')
            return false;
    }
    for (int i = 0; i < p2.size(); i++)
    {
        if (s[p2[i] - 1] == '1')
            return false;
    }
    return true;
}
int main()
{
    int n, c;
    cin >> n >> c;
    string s(n, '1');
    vector<int>p1, p2;
    int a;
    cin >> a;
    while (a != -1)
    {
        p1.push_back(a);
        cin >> a;
    }
    cin >> a;
    while (a != -1)
    {
        p2.push_back(a);
        cin >> a;
    }
    string ask[8] = { s
                  ,caozuo(s,1)
                  ,caozuo(s,2)
                  ,caozuo(s,3)
                  ,caozuo(s,4)
                  ,caozuo(s,5)
                  ,caozuo(s,6)
                  ,caozuo(s,7) };
    vector<string>res;
    if (c == 0 && ifst(s, p1, p2))
    {
        cout << s << endl;
        return 0;
    }
    else if (c == 1)
    {
        for (int i = 1; i < 5; i++)
        {
            if (ifst(ask[i], p1, p2))
            {
                res.push_back(ask[i]);
            }
        }
    }
    else if (c == 2)
    {
        for (int i = 0; i < 8; i++)
        {
            if (i == 4)
            {
                continue;
            }
            if (ifst(ask[i], p1, p2))
            {
                res.push_back(ask[i]);
            }
        }
    }
    else if (c >= 3)
    {
        for (int i = 0; i < 8; i++)
        {
            if (ifst(ask[i], p1, p2))
            {
                res.push_back(ask[i]);
            }
        }
    }
    sort(res.begin(), res.end());
    if (res.empty())
    {
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    for (auto i : res)
    {
        cout << i << endl;
    }
}
